<!-- main/resources/resfile/index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no,   viewport-fit=cover">
    <script>
        function getFile() {
          let file = 'file:///data/storage/el1/bundle/entry/resources/resfile/js/script.js';
          // 使用file协议通过XMLHttpRequest跨域访问本地js文件。
          let xmlHttpReq = new XMLHttpRequest();
          xmlHttpReq.onreadystatechange = function () {
            console.info('readyState:' + xmlHttpReq.readyState);
            console.info('status:' + xmlHttpReq.status);
            if (xmlHttpReq.readyState === 4) {
              if (xmlHttpReq.status === 200) {
                // 如果ets侧正确设置路径列表，则此处能正常获取资源
                const element = document.getElementById('text');
                element.textContent = 'load ' + file + ' success';
              } else {
                // 如果ets侧不设置路径列表，则此处会触发CORS跨域检查错误
                const element = document.getElementById('text');
                element.textContent = 'load ' + file + ' failed';
              }
            }
          };
          xmlHttpReq.open('GET', file);
          xmlHttpReq.send(null);
        }
    </script>
</head>

<body>
<div class="page">
    <button id="example" onclick="getFile()">loadFile</button>
</div>
<div id="text"></div>
</body>

</html>